import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-todolist',
  templateUrl: './todolist.component.html',
  styleUrls: ['./todolist.component.css']
})
export class TodolistComponent implements OnInit {
  public username:any;
  public list:any=[];

  constructor() { }

  ngOnInit(): void {
    this.username="zhangsan"
  }
  getusername(){
    console.log(this.username) //通过双向数据绑定获取新的值
  }
  addusername(e:any){
    if (e.keyCode==13){
      let status=false
      if (this.username=='zhangsan'){
        status=true
      }
      console.log(status)
      var obj={
        username:this.username,
        status:status,
      }
      this.list.push(obj)
      console.log(this.list)
    }
  }
  deleteItem(id:any){
    this.list.splice(id,1)
    console.log(this.list)
  }
  changeData(key:any){
    this.list[key].status=!this.list[key].status
  }
}
